package com.sc.nft.admin.vo;

import com.sc.nft.exception.GlobalRunTimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class ScrollConfigDTO implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "出售价格最低区间")
    private BigDecimal salesMinPrice;

    @ApiModelProperty(value = "出售价格最高区间")
    private BigDecimal salesMaxPrice;

    @ApiModelProperty(value = "出售最小数量")
    private Integer salesMinCount;

    @ApiModelProperty(value = "出售最大数量")
    private Integer salesMaxCount;

    @ApiModelProperty(value = "求购价格最低区间")
    private BigDecimal buyMinPrice;

    @ApiModelProperty(value = "求购价格最高区间")
    private BigDecimal buyMaxPrice;
    @ApiModelProperty(value = "出售订单最大数量")
    private Integer salesOrderMaxCount;
    @ApiModelProperty(value = "求购订单最大数量")
    private Integer buyOrderMaxCount;
    @ApiModelProperty(value = "求购最小数量")
    private Integer buyMinCount;
    @ApiModelProperty("可出售数量限制")
    private Integer salesFreezeCount;
    @ApiModelProperty(value = "求购最大数量")
    private Integer buyMaxCount;

    @ApiModelProperty(value = "本地手续费")
    private BigDecimal inDaoFee;

    @ApiModelProperty(value = "本地最低价格")
    private BigDecimal inDaoAmount;

    @ApiModelProperty(value = "外地额外增加比例")
    private BigDecimal outDaoRatio;

    @ApiModelProperty(value = "外地额外增加价格")
    private BigDecimal outDaoAmount;

    @ApiModelProperty(value = "出售最小手续费")
    private BigDecimal salesMinFeeAmount;

    @ApiModelProperty(value = "出售手续费比例")
    private BigDecimal salesFeeRatio;

    @ApiModelProperty(value = "道具分红池")
    @NotNull(message = "道具分红池不能为空")
    private BigDecimal propsShareRatio;

    @ApiModelProperty(value = "平台分红池")
    @NotNull(message = "平台分红池不能为空")
    private BigDecimal platformShareRatio;

    @ApiModelProperty(value = "股东分红池")
    @NotNull(message = "股东分红池不能为空")
    private BigDecimal shareholderShareRatio;

    @ApiModelProperty(value = "员工分红池")
    @NotNull(message = "员工分红池不能为空")
    private BigDecimal staffShareRatio;

    @ApiModelProperty(value = "版权图省级比例")
    @NotNull(message = "版权图省级比例不能为空")
    private BigDecimal metaMapProvinceRatio;

    @ApiModelProperty(value = "版权图市级比例")
    @NotNull(message = "版权图市级比例不能为空")
    private BigDecimal metaMapCityRatio;

    @ApiModelProperty(value = "版权图区级比例")
    @NotNull(message = "版权图区级比例不能为空")
    private BigDecimal metaMapRegionRatio;


    public void checkRatio() {
        BigDecimal propsShareResult = propsShareRatio.divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
        BigDecimal platformResult = platformShareRatio.divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
        BigDecimal shareholderResult = shareholderShareRatio.divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
        BigDecimal staffShareResult = staffShareRatio.divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
        //metaMapRatio这里不要乘100 前端已经处理过了
        BigDecimal add = propsShareResult.add(platformResult).add(shareholderResult).add(staffShareResult).add(metaMapProvinceRatio).add(metaMapCityRatio).add(metaMapRegionRatio);
        if (add.compareTo(BigDecimal.ONE) > 0) {
            throw new GlobalRunTimeException("总分润比例合计大于100%");
        }
    }


}
